require.config(require_config);

define([
    'jquery',
    'common',
    'ready',
    'template',
    'collection',
    'model',
    'dialog',
    'calendar',
    'datepicker'
], function ($, common, ready, template, Collection, Model, dialog, calendar, datepicker) {

    var index = function () {
        this.init();
    };
    index.prototype = {
        init: function () {

            this.event();
            this.fetch();
        },

        fetch: function () {
            var _this = this;
            this.collection = new Collection({
                container: 'data-list',
                template: 'data-item',
                url: _global.url.api + 'repate_active',
                condition: {
                    limit: 10,
                    offset: 0
                },
                model: {
                    tag_name: 'tr',
                    url: _global.url.api + '',
                    event: {}
                },
                callback: function () {
                    loaded();
                }
            });
            this.collection.fetch();
        },
        event: function () {
            var _this = this;
            //日期
            $('.long_date').on('click', function () {
                WdatePicker({
                    el: this.id,
                    dateFmt: 'yyyy-MM-dd'
                });
            });

            $('#btn-search').on('click', function (e) {
                e.preventDefault();
                _this.collection.condition.start_time = $('input[name="begintime"]').val();
                _this.collection.reload();
            });

        }
    };

    new index();

});